package com.ruoyi.business.controller;

import com.ruoyi.business.domain.Depart;
import com.ruoyi.business.service.IDepartService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 *
 * @author win
 * @date 2021-06-14
 */
@RestController
@RequestMapping("/Depart/depart")
public class DepartController extends BaseController
{
    @Autowired
    private IDepartService departService;

    /**
     *
     */
//    @PreAuthorize("@ss.hasPermi('business:content:list')")
    @GetMapping("/list")
    public TableDataInfo list(Depart depart)
    {
        startPage();
        List<Depart> list = departService.selectDepartList(depart);
        return getDataTable(list);
    }

    /**
     *
     */
//    @PreAuthorize("@ss.hasPermi('business:content:export')")
    @Log(title = "Depart", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Depart depart)
    {
        List<Depart> list = departService.selectDepartList(depart);
        ExcelUtil<Depart> util = new ExcelUtil<Depart>(Depart.class);
        return util.exportExcel(list, "Depart数据");
    }

    /**
     *
     */
//    @PreAuthorize("@ss.hasPermi('business:content:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(departService.selectDepartById(id));
    }

    /**
     *
     */
//    @PreAuthorize("@ss.hasPermi('business:content:add')")
    @Log(title = "Depart", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Depart depart)
    {
        return toAjax(departService.insertDepart(depart));
    }

    /**
     *
     */
//    @PreAuthorize("@ss.hasPermi('business:content:edit')")
    @Log(title = "Depart", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Depart depart)
    {
        return toAjax(departService.updateDepart(depart));
    }

    /**
     *
     */
//    @PreAuthorize("@ss.hasPermi('business:content:remove')")
    @Log(title = "Depart", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(departService.deleteDepartByIds(ids));
    }

    @GetMapping("/departByBelong/{belong}")
    public AjaxResult getDepartByBelong(@PathVariable Long belong) {return AjaxResult.success(departService.getDepartByBelong(belong));}
}
